<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/10 0010
 * Time: 13:35
 */
$server = new Swoole\Server('0.0.0.0', 9801);

$key = ftok(__DIR__, 1);

$server->set([
    'worker_num' => 1, //设置进程
    //'heartbeat_idle_time'=>10,//连接最大的空闲时间
    //'heartbeat_check_interval'=>3 //服务器定时检查
    'task_worker_num' => 1,  //task进程数
    'task_ipc_mode' => 2,
    'message_queue_key' => $key,
    'open_length_check' => 1,
    'package_length_type' => 'N',//设置包头的长度
    'package_length_offset' => 0, //包长度从哪里开始计算
    'package_body_offset' => 4,  //包体从第几个字节开始计算
]);

$server->on('start', function () {
    // include 'index.php'; 不能
});

$server->on('Shutdown', function () {
    // include 'index.php'; 不能
    echo "正常关闭";
});

$server->on('workerStart', function ($server, $worker_id) {
    //include 'index.php';
    if ($server->taskworker) {
        echo 'task_worker:' . $server->worker_id . PHP_EOL;
    } else {

    } echo 'worker:'.$server->worker_id.PHP_EOL;
});
//监听事件,连接事件
$server->on('connect',function ($server,$fd){

    //echo "新的连接进入xxx:{$fd}".PHP_EOL;
});
